package com.example.smartcity.ui.Adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.example.smartcity.R;
import com.example.smartcity.ui.Bean.ItemCode;

import java.util.ArrayList;
import java.util.List;

public class OrderArrayAdapter extends ArrayAdapter<ItemCode> {
    private ArrayList<ItemCode> list;
    private int resource;
    public OrderArrayAdapter(@NonNull Context context, int resource, @NonNull ArrayList<ItemCode> list) {
        super(context, resource, list);
        this.resource = resource;
        this.list = list;
    }

    @NonNull
    @Override
    public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
        ItemCode itemCode = getItem(position);
        View view = null;
        ViewHolder viewHolder = null;
        if (convertView==null){
            view = LayoutInflater.from(getContext()).inflate(resource,parent,false);
            viewHolder = new ViewHolder();
            viewHolder.TV_end = view.findViewById(R.id.TV_End);
            viewHolder.TV_orderNum = view.findViewById(R.id.TV_orderNumber);
            viewHolder.TV_price = view.findViewById(R.id.TV_Price);
            viewHolder.TV_start = view.findViewById(R.id.TV_Start);
            viewHolder.TV_userName = view.findViewById(R.id.TV_userName);
            viewHolder.TV_userTel =view.findViewById(R.id.TV_UseTel);
            viewHolder.TV_path = view.findViewById(R.id.TV_path);
            view.setTag(viewHolder);
        }else{
            view = convertView;
            viewHolder = (ViewHolder) view.getTag();
        }
        viewHolder.TV_path.setText(itemCode.getPath());
        viewHolder.TV_userTel.setText(itemCode.getUserTel());
        viewHolder.TV_userName.setText(itemCode.getUserName());
        viewHolder.TV_start.setText(itemCode.getStart());
        viewHolder.TV_end.setText(itemCode.getEnd());
        viewHolder.TV_price.setText("￥"+itemCode.getPrice());
        viewHolder.TV_orderNum.setText(itemCode.getOrderNum());
        return view;
    }

    class ViewHolder{
        TextView TV_orderNum;
        TextView TV_price;
        TextView TV_start;
        TextView TV_end;
        TextView TV_path;
        TextView TV_userName;
        TextView TV_userTel;
    }
}
